//
//  ICMyRedPacketTableViewCell.m
//  ICome
//
//  Created by luoziheng on 2016/11/9.
//  Copyright © 2016年 iCom. All rights reserved.
//

#import "ICMyRedPacketTableViewCell.h"
#import "ICHeaderFile.h"

@interface ICMyRedPacketTableViewCell()

@property (nonatomic, strong) UILabel *stateLabel;
@property (nonatomic, strong) UILabel *dateLabel;
@property (nonatomic, strong) UILabel *sourceLabel;
@property (nonatomic, strong) UILabel *amountValueLabel;

@end

@implementation ICMyRedPacketTableViewCell

- (id)initWithStyle:(UITableViewCellStyle)cell reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:cell reuseIdentifier:reuseIdentifier];
    if (self) {
        [self layoutSubview];
    }
    return self;
}

- (void)layoutSubview {
    
    [self.stateLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.mas_left).offset(15);
        make.top.equalTo(self.mas_top).offset(13);
        make.width.mas_equalTo(200);
        make.height.mas_equalTo(20);
    }];
    [self.dateLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.stateLabel.mas_left);
        make.top.equalTo(self.stateLabel.mas_bottom).offset(9);
        make.width.equalTo(self.stateLabel.mas_width);
        make.height.mas_equalTo(15);
    }];
    [self.sourceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.stateLabel.mas_left);
        make.top.equalTo(self.dateLabel.mas_bottom).offset(4);
        make.width.equalTo(self.stateLabel.mas_width);
        make.height.mas_equalTo(15);
    }];
    [self.amountValueLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.mas_top).offset(10);
        make.right.equalTo(self.mas_right).offset(-18);
        make.bottom.equalTo(self.mas_bottom).offset(-10);
        make.left.equalTo(self.dateLabel.mas_right).offset(15);
    }];
}

- (void)setModel:(ICHistoryListModel *)model {
    if ([model.type isEqualToString:@"1"]) {
        self.stateLabel.text = @"发出红包";
        self.amountValueLabel.text = [NSString stringWithFormat:@"-%@", model.amount];
        self.amountValueLabel.textColor = ICRGB(0xe44e4e);
    }else if ([model.type isEqualToString:@"2"]) {
        self.stateLabel.text = @"收到红包";
        self.amountValueLabel.text = [NSString stringWithFormat:@"+%@", model.amount];
        self.amountValueLabel.textColor = ICRGB(0x89c44d);
    }else if ([model.type isEqualToString:@"3"]) {
        self.stateLabel.text = @"红包退款";
        self.amountValueLabel.text = [NSString stringWithFormat:@"+%@", model.amount];
        self.amountValueLabel.textColor = ICRGB(0x89c44d);
    }
    self.dateLabel.text = [model.createDate getDateWithTimestamp:model.createDate];
    self.sourceLabel.text = model.describe;
}

+ (CGFloat)cellHeight {
    return 86;
}

#pragma mark - Getter

- (UILabel *)stateLabel {
    if (!_stateLabel) {
        _stateLabel = [[UILabel alloc] init];
        _stateLabel.textColor = ICRGB(0x333333);
        _stateLabel.font = ICFont(15.0 * Level);
        [self.contentView addSubview:_stateLabel];
    }
    return _stateLabel;
}

- (UILabel *)dateLabel {
    if (!_dateLabel) {
        _dateLabel = [[UILabel alloc] init];
        _dateLabel.textColor = ICRGB(0x999999);
        _dateLabel.font = ICFont(12.0 * Level);
        [self.contentView addSubview:_dateLabel];
    }
    return _dateLabel;
}

- (UILabel *)sourceLabel {
    if (!_sourceLabel) {
        _sourceLabel = [[UILabel alloc] init];
        _sourceLabel.textColor = ICRGB(0x999999);
        _sourceLabel.font = ICFont(12.0 * Level);
        [self.contentView addSubview:_sourceLabel];
    }
    return _sourceLabel;
}

- (UILabel *)amountValueLabel {
    if (!_amountValueLabel) {
        _amountValueLabel = [[UILabel alloc] init];
        _amountValueLabel.textColor = ICRGB(0x5f6f95);
        _amountValueLabel.font = ICFont(17.0 * Level);
        _amountValueLabel.textAlignment = NSTextAlignmentRight;
        [self.contentView addSubview:_amountValueLabel];
    }
    return _amountValueLabel;
}

@end
